package com.linkage.order.service;

import java.util.List;
import java.util.UUID;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.linkage.book.pojo.Book;
import com.linkage.order.pojo.Order;
import com.linkage.order.repository.OrderRepository;
/**
 * 
 * @author XiaMingYu
 *
 */
@Service
public class OrderService {
	@Autowired
	private OrderRepository orderRepository;
	//private OrderLineRepository orderLineRepository;
	private Order order;
	
	public List<Order> queryAll(){

		return this.orderRepository.queryAll();		
	}
		
	/*public List<OrderLine> queryItem(){
		return this.orderLineRepository.queryItem();
	}*/
	
	public void saveOrder(Order order){
		order.setorderId(UUID.randomUUID().toString());
	}
	
	public void deleteOrder(String orderId){
		this.orderRepository.deleteOrder(orderId);
	}
	
	public Order findOrderById(String orderId){
		return this.orderRepository.findOrderById(orderId);
	}
	
	/*public OrderLine findOrderFormBookById(int orderFormBookId){
		return this.orderRepository.findOrderFormBookById(orderFormBookId);
	}*/
	
	/*public double calTotal(int bookId ,int bookIdQuantity ){
		book = this.bookRepository.findBookById(bookId);
	    double subTotal = book.getPrice()*bookIdQuantity ;
		return subTotal;
	}*/
	
	public void payOrder(String orderId){
	this.orderRepository.payOrder(orderId);
	}
	
	public void deliver(String orderId){
	    order = this.orderRepository.findOrderById(orderId);
		if(order.getStatus()!=2){
			return;
		}
		else 
		order.setStatus(3);
		return;
	}
	
	public void confirm(Order order){
		this.orderRepository.confirm(order);
		order.setStatus(4);
		}
	
	public Order loadOneOrder(String orderId){
		return this.orderRepository.loadOneOrder(orderId);
	}
}



